<template>
  <div>
    <el-dialog title="指 标"
               :visible.sync="visible"
               v-loading="loading"
               :before-close="modalClose"
               :close-on-click-modal="false"
               :close-on-press-escape="false"
               width="70%">
      <el-button type="primary"
                 @click="handleAdd()">新 增
      </el-button>

      <element-table class="mt-20"
                     :columns="columns"
                     :data="tableData"
                     v-loading="loading"
                     pager
                     :pageTotal="pageTotal"
                     :pageIndex="pageIndex"
                     :pageSize="pageSize"
                     @handleChangePage="handleChangePage">
        <template v-slot:option="{row}">
          <el-button type="primary"
                     @click="handleOption('edit', row)">编辑
          </el-button>
          <el-button type="danger"
                     @click="handleOption('del', row)">删除
          </el-button>
          <el-button type="warning"
                     @click="handleOption('panduan', row)">{{row.isConfigureJudge===1?'条件判断(已配置)':'条件判断(未配置)'}}
          </el-button>
          <el-button type="warning"
                     @click="handleOption('config', row)">推荐服务配置
          </el-button>
        </template>
      </element-table>

    </el-dialog>
    <!--    编辑-->
    <target-edit-dialog :eventdata="eventdata"
                        v-if="showEidtDialog"
                        :visible.sync="showEidtDialog"/>
    <!-- 推荐服务配置   -->
    <serviceconfig-dialog :eventdata="eventdata"
                          v-if="showServiceConfigDialog"
                          :visible.sync="showServiceConfigDialog"/>
    <!-- 推荐服务配置   -->
    <judge-dialog :eventdata="eventdata"
                  v-if="conditionShow"
                  :visible.sync="conditionShow"/>


  </div>
</template>
<script>
import ElementTable from '@/base/ElementTable'
import serviceConfigDialog from "./serviceConfigDialog";
import targetEditDialog from "./targetEditDialog";
import judgeDialog from "./judgeDialog";

export default {
  name: 'zhibiaoDialog', // 病种管理
  props: {
    dataObj: {
      type: Object,
      default: {}
    },
    visible: {
      type: Boolean,
      default: false
    }
  },

  data() {
    return {


      tableData: [],
      columns: [
        {
          label: '项目及意义',
          prop: 'projectName',
          align: "center"
        },
        {
          label: '管理目标',
          prop: 'targetManagement',
          align: "center"
        },
        {
          label: '针对的主要健康风险',
          prop: 'healthRisks',
          align: "center"
        }, {
          label: '排序',
          prop: 'sortNum',
          align: 'center'
        }, {
          label: '操作',
          prop: 'option',
          align: 'center',
          isSlot: true,
          width: 450
        }
      ],

      showServiceConfigDialog: false,
      conditionShow: false,
      loading: false,
      pageTotal: 0,
      pageIndex: 1,
      pageSize: 20,
      diseaseId: '',
      eventdata: {},
      showEidtDialog: false

    }

  },

  methods: {
    modalClose() {
      this.$emit('update:visible', false); // 直接修改父组件的属性
    },


    //获取列表
    getHealthMapTargetList() {
      this.post(this.api.healthMap.getHealthMapTargetList, {
        diseaseId: this.diseaseId,
        pageIndex: this.pageIndex - 1,
        pageSize: this.pageSize
      }).then((res) => {
        if (res.data.code === '200') {
          this.tableData = res.data.object
          this.pageTotal = res.data.totalNum
        }
      })
    },

    //新增
    handleAdd() {
      this.eventdata.childId = ''
      this.showEidtDialog = true
    },

    async handleOption(op, row) {
      switch (op) {
        case 'edit':
          this.eventdata.childId = row.id
          this.showEidtDialog = true
          break
        case 'del':
          this.$confirm('确认删除？', '提示', {
            type: 'warning'
          }).then(() => {
            this.post(this.api.healthMap.delHealthMapTarget, {
              id: row.id
            }).then((res) => {
              if (res.data.code === '200') {
                this.$message.success('删除成功')
                this.getHealthMapTargetList()
              }
            })
          })
          break
        case 'panduan':
          this.eventdata.childId = row.id
          this.conditionShow = true
          break
        case 'config':
          this.showServiceConfigDialog = true
          this.eventdata.childId = row.id
          break

      }
    },


    // 分页
    handleChangePage(page) {
      this.pageIndex = page;
      this.getHealthMapTargetList();
    },

  },
  created() {
    this.diseaseId = this.dataObj.id
    this.eventdata.diseaseId = this.dataObj.id

    this.getHealthMapTargetList()

  },
  components: {
    'element-table': ElementTable,
    'serviceconfig-dialog': serviceConfigDialog,
    'target-edit-dialog': targetEditDialog,
    'judge-dialog': judgeDialog
  }


}
</script>
<style scoped lang="scss">

</style>
